home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-07-15 | 4.2 KB | 117 lines | [TEXT/MPS ] |
-
- PROGRAM OpenWindow;
-
- USES MemTypes,SysEqu,OSUtils,ToolUtils,SegLoad,Fonts,Retrace,
- QuickDraw,PackIntf,Resources,OSEvents,Events,Memory,Script;
-
- VAR
- WindTitle : Str255;
- MyWindow,aWindPtr : WindowPtr;
- err : integer;
- MyEvent : EventRecord;
- quit,DrawOn : boolean;
- WindRect : Rect;
- aPoint : point;
- myCrsr : CursHandle;
-
- {------------------------------------------------------------------------------------}
-
- PROCEDURE _DataInit; EXTERNAL;
-
- {------------------------------------------------------------------------------------}
-
- PROCEDURE InitMac;
-
- BEGIN {InitMac} {the big inits}
-
- UnLoadSeg(@_DataInit); {remove data initialization code before any allocations}
- InitGraf(@thePort); {initialize QuickDraw}
- InitFonts; {initialize Font Manager}
- FlushEvents(everyEvent, 0); {call OS Event Mgr to discard any previous events}
- InitWindows; {initialize Window Manager}
- InitCursor; {call QuickDraw to make cursor (pointer) an arrow}
- quit := false;
- DrawOn := false;
-
- END; {InitMac}
-
- {------------------------------------------------------------------------------------}
-
- PROCEDURE DoDraw;
-
- BEGIN
- DrawOn := true;
- GlobalToLocal (Myevent.where);
- MoveTo (Myevent.where.h,Myevent.where.v);
- EraseRect (WindRect);
- END;
-
- {------------------------------------------------------------------------------------}
-
- BEGIN {main PROGRAM}
-
- InitMac; {'nitialize them Mac Managers}
-
- {Now let's figure out how big the (main) screen is, and make a Rect that fits inside it}
- {Screenbits.bounds always has the Rect of the main screen}
-
- WindRect.top := screenBits.bounds.top + GetMBarHeight+25;
- WindRect.left := screenBits.bounds.left + 5;
- WindRect.bottom := screenBits.bounds.bottom - 5;
- WindRect.right := screenBits.bounds.right - 5;
-
- WindTitle := ('Press "q" to quit'); {the window title will tell the user how to quit this program}
-
- MyWindow := NewWindow {we'll make a window with NewWindow, cuz we don't want to carry}
- { a resource around}
- (nil, {let the window manager take care of storing the window record}
- WindRect, {this is our "custom tailored to the scereen" rect}
- WindTitle, {our famous "user interface in the window title" title}
- true, {the visible boolean, we'd like to see our}
- noGrowDocProc, {this tells NewWindow what kind of window we want}
- Pointer(-1), {this param is the pointer to the window we want to be behind}
- { in this case, we want to be frontmost, and Pointer(-1) does that}
- true, {this is true, so we can have a "go away" box in the title bar}
- 1); {refCon - a reference number; used by the app for whatever it wants to.}
-
- if MyWindow <> nil then {make sure the new window pointer is valid}
- begin
- SetPort (MyWindow); {set the current graf port to our new window}
- GlobalToLocal (WindRect.topLeft); {make our Window Rect local coords so erase rect will do the right thing}
- GlobalToLocal (WindRect.botRight);
- myCrsr := GetCursor (crossCursor); {we'll use the crosshair cursor}
- if myCrsr <> nil then
- begin
- MoveHHi (handle(myCrsr)); {move the cursor data high in the heap to avoid fragmentation}
- HLock (handle(myCrsr)); {now lock the handle down}
- SetCursor (cursor(myCrsr^^)); {and finally set the cursor to the crosshair}
- repeat
- if not DrawOn then {DrawOn is sort of a "mouse down in content region" flag}
- begin
- if GetNextEvent (EveryEvent,MyEvent) then {only check for events when mouse is up}
-
- CASE MyEvent.what of
-
- mouseDown : if ((FindWindow (MyEvent.where,aWindPtr) = inContent) {make sure the mouseDown is}
- {where we want it}
- and (aWindptr = MyWindow)) then DoDraw
- else if FindWindow (MyEvent.where,aWindPtr) = inGoAway then Quit := true;
-
- KeyDown : if (char(BitAnd (MyEvent.message,charCodeMask)) = 'q') then quit := true;
-
- end; {case}
- end
- else
- begin
- If StillDown then {if mouse btn is still down, keep drawing}
- begin
- GetMouse (aPoint); {see where the mouse is pointing now}
- StdLine (aPoint); { and draw a line to it}
- end
- else DrawOn := false; {if the mouse btn isn't down, stop drawing}
- end;
- until quit;
- end;
- end;
-
- END.